home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Prog / B-C / C Servant™.cpt / C Servant™.rsrc / TEXT_130_aText.txt < prev    next >
Encoding:
Text File  |  1992-02-24  |  1.9 KB  |  31 lines

  1.  
  2. 3. A Working C Program; Variables; Types and Type Declarations
  3.  
  4.             Here‚Äôs a bigger program that adds three integers and prints their sum.
  5.  
  6.             main( ) {
  7.                         int a, b, c, sum;
  8.                         a = 1; b = 2; c = 3;
  9.                         sum = a + b + c;
  10.                         printf(‚Äúsum is %d‚Äù, sum);
  11.             }
  12.  
  13.             Arithmetic and the assignment statements are much the same as in Fortran (except for the semicolons) or PL/I. The format of C programs is quite free. We can put several statements on a line if we want, or we can split a statement among several lines if it seems desirable. The split may be between any of the operators or variables, but NOT in the middle of a name or operator. As a matter of style, spaces, tabs, and newlines should be used freely to enhance readability.
  14.  
  15.             C has four fundamental types of variables:
  16.  
  17.             int                             integer (PDP-11: 16 bits; H6070: 36 bits; IBM360: 32 bits)
  18.             char                         one byte character (PDP-11, IBM360: 8 bits; H6070: 9 bits)
  19.             float                     single-precision floating point
  20.             double                 double-precision floating point
  21.  
  22. There are also arrays and structures of these basic types, pointers to them and functions that return them, all of which we will meet shortly.
  23.  
  24.             All variables in a C program must be declared, although this can sometimes be done implicitly by context. Declarations must precede executable statements. The declaration
  25.  
  26.             int a, b, c, sum;
  27.  
  28. declares a, b, c, and sum to be integers.
  29.  
  30.             Variable names have one to eight characters, chosen from A-Z, a-z, 0-9, and _, and start with a non-digit. Stylistically, it‚Äôs much better to use only a single case and give functions and external variables names that are unique in the first six characters. (Function and external variable names are used by various assemblers, some of which are limited in the size and case of identifiers they can handle.) Furthermore, keywords and library functions mayonly be recognized in one case.
  31.